package com.zr.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
 * 建立连接数据库的工具类
 * @author Administrator
 *
 */
public class JdbcUtil {
	 private  static final String   DriverName = "com.mysql.jdbc.Driver";
	 private  static final String   DBUrl = "jdbc:mysql://localhost:3306/dormmanagesystems?useUnicode=true&characterEncoding=UTF8";
	 private  static final String   DBUname = "root";
	 private  static final String   DBPsw = "123";
	/**
	 * 获取数据库的链接
	 * @return
	 */
	    public  static  Connection   getDBConnection(){
	    	  Connection  con = null;
	    	  try {
				Class.forName(DriverName);
				con = DriverManager.getConnection(DBUrl, DBUname, DBPsw);
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    	  return  con;
	    }
	/**
	 * 关闭数据库的链接
	 * @param con
	 */

	    public  static  void closedConnection(Connection  con){
	    	 if(con!=null){
	    		 try {
					con.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	    	 }
	    }
	    

}
